home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 333_01 / awk.h < prev    next >
C/C++ Source or Header  |  1989-02-18  |  18KB  |  542 lines

  1.  
  2. /***************************************************************************/
  3. /*                                       */
  4. /*               awk.h -- Definitions for gawk.               */
  5. /*                                       */
  6. /*         Copyright (C) 1986 Free Software Foundation           */
  7. /*             Written by Paul Rubin, August 1986            */
  8. /*                                       */
  9. /***************************************************************************/
  10. /*                                       */
  11. /* GAWK is distributed in the hope that it will be useful, but WITHOUT ANY */
  12. /* WARRANTY.  No author or distributor accepts responsibility to anyone    */
  13. /* for the consequences of using it or for whether it serves any       */
  14. /* particular purpose or works at all, unless he says so in writing.       */
  15. /* Refer to the GAWK General Public License for full details.           */
  16. /*                                       */
  17. /* Everyone is granted permission to copy, modify and redistribute GAWK,   */
  18. /* but only under the conditions described in the GAWK General Public       */
  19. /* License.  A copy of this license is supposed to have been given to you  */
  20. /* along with GAWK so you can know your rights and responsibilities.  It   */
  21. /* should be in a file named COPYING.  Among other things, the copyright   */
  22. /* notice and this notice must be preserved on all copies.           */
  23. /*                                       */
  24. /* In other words, go ahead and share GAWK, but don't try to stop          */
  25. /* anyone else from sharing it farther.  Help stamp out software hoarding! */
  26. /*                                       */
  27. /***************************************************************************/
  28.  
  29. #ifndef AWK_H
  30. #define AWK_H
  31.  
  32.  
  33. #define AWKNUM              double
  34.  
  35. #include "regex.h"
  36.  
  37. #include <ctype.h>
  38. #define is_identchar(c)       (isalnum(c) || (c) == '_')
  39.  
  40. #define obstack_chunk_alloc    malloc
  41. #define obstack_chunk_free     free
  42. #include "obstack.h"
  43.  
  44. #define PROFILER           TRUE
  45.  
  46. #if PROFILER
  47. #define STATIC
  48. #else
  49. #define STATIC               static
  50. #endif
  51.  
  52. #define EOS               '\0'
  53. #define FPTR               void far *
  54.  
  55. #if defined(__POWERC)
  56. #define NEAR
  57. #define PASCAL
  58. #define CDECL
  59. #define VOID               int
  60. #else
  61. #define NEAR               near
  62. #define PASCAL               pascal
  63. #define CDECL               cdecl
  64. #define VOID               void
  65. #endif
  66.  
  67. #define TABSTOPS           8
  68.  
  69. #define MAXDIM(array)           (sizeof(array) / sizeof(array[0]))
  70.  
  71. #define MAX_SUBSCRIPT_LEN      80
  72.  
  73. #ifndef TRUE
  74. #define TRUE               1
  75. #define FALSE               0
  76. #endif
  77.  
  78. typedef int               BOOL;
  79.  
  80. /*  illegal node entry                                */
  81. #define NODE_ILLEGAL        0
  82.  
  83. /*  binary operators - lnode and rnode are the expressions to work on        */
  84. #define NODE_EXPONENTIAL    1
  85. #define NODE_TIMES        2
  86. #define NODE_QUOTIENT        3
  87. #define NODE_MOD        4
  88. #define NODE_PLUS        5
  89. #define NODE_MINUS        6
  90. #define NODE_COND_PAIR        7
  91. #define NODE_SUBSCRIPT        8
  92. #define NODE_CONCAT        9
  93.  
  94. /* unary operators - subnode is the expression to work on            */
  95. #define NODE_PREINCREMENT    10
  96. #define NODE_PREDECREMENT    11
  97. #define NODE_POSTINCREMENT    12
  98. #define NODE_POSTDECREMENT    13
  99. #define NODE_UNARY_MINUS    14
  100. #define NODE_FIELD_SPEC     15
  101.  
  102. /* assignment operators - lnode is the var to assign to rnode is the exp    */
  103. #define NODE_ASSIGN        16
  104. #define NODE_ASSIGN_EXPONENTIAL 17
  105. #define NODE_ASSIGN_TIMES    18
  106. #define NODE_ASSIGN_QUOTIENT    19
  107. #define NODE_ASSIGN_MOD     20
  108. #define NODE_ASSIGN_PLUS    21
  109. #define NODE_ASSIGN_MINUS    22
  110.  
  111. /*  boolean binary operators - lnode and rnode are expressions            */
  112. #define NODE_AND        23
  113. #define NODE_OR         24
  114.  
  115. /*  relational binary operators - lnode and rnode are exp to comapre        */
  116. #define NODE_EQUAL        25
  117. #define NODE_NOTEQUAL        26
  118. #define NODE_LESS        27
  119. #define NODE_GREATER        28
  120. #define NODE_LEQ        29
  121. #define NODE_GEQ        30
  122.  
  123. /*  relational unary operators - subnode is the expression to operate on    */
  124. #define NODE_NOT        31
  125.  
  126. /*  match operators - lnode is an exp, rnode is a regular expression        */
  127. #define NODE_MATCH        32
  128. #define NODE_NOMATCH        33
  129.  
  130. /*  data items                                    */
  131. #define NODE_STRING        34  /* stptr and stlen                */
  132. #define NODE_TEMP_STRING    35  /* stptr and stlen                */
  133. #define NODE_NUMBER        36  /* numbr                    */
  134.  
  135. /*  program structures                                */
  136. #define NODE_RULE_LIST        37  /* lnode is rule, rnode rest of list    */
  137. #define NODE_RULE_NODE        38  /* lnode is cond, rnode is statement    */
  138. #define NODE_STATEMENT_LIST    39  /* lnode is stmt, rnode is more list    */
  139. #define NODE_IF_BRANCHES    40  /* lnode is TRUE side, rnode is FALSE   */
  140. #define NODE_EXPRESSION_LIST    41  /* lnode is an exp, rnode is more list  */
  141.  
  142. /*  keywords                                    */
  143. #define NODE_K_BEGIN        42  /* nothing on either side            */
  144. #define NODE_K_END        43  /* nothing on either side            */
  145. #define NODE_K_IF        44  /* lnode is cond, rnode is if_branches  */
  146. #define NODE_K_WHILE        45  /* lnode is cond, rnode stuff to run    */
  147. #define NODE_K_FOR        46  /* lnode is for_struct, rnode run stuff */
  148. #define NODE_K_ARRAYFOR     47  /* lnode is for_struct, rnode run stuff */
  149. #define NODE_K_BREAK        48  /* nothing on either side            */
  150. #define NODE_K_CONTINUE     49  /* nothing on either side            */
  151. #define NODE_K_PRINT        50  /* lnode is exp_list, rnode is redirect */
  152. #define NODE_K_PRINTF        51  /* lnode is exp_list, rnode is redirect */
  153. #define NODE_K_NEXT        52  /* nothing on either side            */
  154. #define NODE_K_EXIT        53  /* subnode is return value, or NULL     */
  155. #define NODE_K_DELETE        54  /* lnode is symbol, rnode is subscript  */
  156. #define NODE_GETLINE        55  /* lnode is var, rnode is redirect        */
  157.  
  158. /*  I/O redirection for print statements                    */
  159. #define NODE_REDIRECT_INPUT    56  /* subnode is where to redirect        */
  160. #define NODE_REDIRECT_OUTPUT    57  /* subnode is where to redirect        */
  161. #define NODE_REDIRECT_APPEND    58  /* subnode is where to redirect        */
  162. #define NODE_REDIRECT_PIPE    59  /* subnode is where to redirect        */
  163.  
  164. /*  variables                                    */
  165. #define NODE_VAR        60  /* rnode is value, lnode array stuff    */
  166. #define NODE_VAR_ARRAY        61  /* array is ptr to elements, asize = #  */
  167.  
  168. /*  builtin functions - subnode is exp_list, proc is function to call        */
  169. #define NODE_BUILTIN        62
  170.  
  171. /*  line range pattern                                */
  172. #define NODE_LINE_RANGE     63
  173.  
  174. /*  conditional expression                            */
  175. #define NODE_CONDEXP        64  /* lnode is cond, rnode is cond_branches*/
  176. #define NODE_CONDEXP_BRANCHES    65  /* lnode is exp if TRUE, rnode if FALSE */
  177.  
  178. /*  regular expression                                */
  179. #define NODE_REGEXP        66
  180.  
  181. /*  membership conditional                            */
  182. #define NODE_MEMBER_COND    67
  183.  
  184.  
  185. typedef struct exp_node
  186. {
  187.     int                       type;
  188.     union
  189.     {
  190.     struct
  191.     {
  192.         struct exp_node              *lptr;
  193.         union
  194.         {
  195.         struct exp_node           *rptr;
  196.         struct exp_node        *(PASCAL *pptr)(struct exp_node *);
  197.         REPAT_BUFFER             *preg;
  198.         struct for_loop_header         *hd;
  199.         struct ahash            **av;
  200.         int                  r_ent; /* range entered (jfw) */
  201.         } r;
  202.     } nodep;
  203.     struct
  204.     {
  205.         struct exp_node            **ap;
  206.         int                   as;
  207.     } ar;
  208.     struct
  209.     {
  210.         char                 *sp;
  211.         int                   slen, sref;
  212.     } str;
  213.     AWKNUM                      fltnum;
  214.   } sub;
  215. } NODE;
  216.  
  217. #define lnode           sub.nodep.lptr
  218. #define rnode           sub.nodep.r.rptr
  219.  
  220. #define subnode        lnode
  221. #define proc           sub.nodep.r.pptr
  222.  
  223. #define reexp           lnode
  224. #define rereg           sub.nodep.r.preg
  225.  
  226. #define forsub           lnode
  227. #define forloop        sub.nodep.r.hd
  228.  
  229. #define array           sub.ar.ap
  230. #define arrsiz           sub.ar.as
  231.  
  232. #define stptr           sub.str.sp
  233. #define stlen           sub.str.slen
  234. #define stref           sub.str.sref
  235.  
  236. #define numbr           sub.fltnum
  237.  
  238. #define var_value       lnode
  239. #define var_array       sub.nodep.r.av
  240.  
  241. #define condpair       lnode
  242. #define triggered       sub.nodep.r.r_ent
  243.  
  244. #define HASHSIZE       101
  245. #define ASSOC_HASHSIZE       29
  246. #define STIR_BITS(n)       ((n) << 5 | (((n) >> 27) & 0x1f))
  247. #define HASHSTEP(old, c)   ((old << 1) + c)
  248. #define MAKE_POS(v)       (((v) < 0) ? -(v) : (v))
  249.  
  250. /* the following defines are used in calls to assoc_lookup() to advise the  */
  251. /* function of the type of action desired on the subscripted variable.        */
  252. #define ASSOC_CREATE       0    /* if var doesn't exist, create it          */
  253. #define ASSOC_TEST       1    /* test if var exists, don't create         */
  254. #define ASSOC_DELE